﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smart.Model;
using Smart.Data.ExerciseCalculation;
using Smart.Data;

namespace Smart.Business.ExerciseCalculation
{
    public class ExerciseBL
    {
        private ExerciseDL dal = null;

        public ExerciseBL()
        {
            if (dal == null)
            {
                dal = new ExerciseDL(null);
            }
        }

        public ExerciseBL(ISmartEntities context)
        {
            if (dal == null)
            {
                dal = new ExerciseDL(context);
            }
        }

        public List<ExerciseCategory> GetAllCategories()
        {
            return dal.GetAllCategories().ToList();
        }

        public List<Exercise> GetAllExercises()
        {
            return dal.GetAllExercises().ToList();
        }

        public Exercise GetExerciseById(int ExId)
        {
            return dal.GetExerciseById(ExId);
        }

        public List<Exercise> GetExercisesByCategory(int cat)
        {

            return dal.GetExercisesByCategory(cat);
        }

        public double CalculateBurnedCalories(int ExId, int duration)
        {
            return dal.CalculateBurnedCalories(ExId, duration);
        }

        public void RecordExercise(int userId, int ExId, int _duration)
        {
            double res = CalculateBurnedCalories(ExId, _duration);
            ExerciseLog ex = new ExerciseLog();
            ex.UserId = userId;
            ex.ExerciseDate = DateTime.Now;
            ex.ExerciseId = ExId;
            ex.Duration = _duration;
            ex.BurnedCals = (int)res;

            dal.RecordExercise(ex);

        }
    }
}
